/**
 * 
 */
package inz.model.patterns;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Random;

/** Generates random database sequences */
public class SequenceGenerator
{
	/** generates files with database sequences
	 * @param elements list of elements to create sequences from
	 * @param dirPath relative path to folder where files with sequences will be saved
	 * @param howMany number of database sequences to generate
	 * @param seqLength number of elements in every sequence */
	public static void generate(String[] elements, String dirPath, int howMany, int seqLength)
	{
		try
		{
			File dirFile = new File(dirPath);
			dirFile.mkdirs();
			Random random = new Random(System.currentTimeMillis());
			for (int i = 1; i <= howMany; i++)
			{
				BufferedWriter writer = new BufferedWriter(new FileWriter(dirPath + "seq" + i + ".txt"));
				String line = "";
				for (int k = 0; k < seqLength; k++)
				{
					line += elements[random.nextInt(elements.length)] + " ";
					if (k % 10 == 9)
					{
						line += System.getProperty("line.separator");
					}
				}
				writer.write(line);
				writer.close();
			}
		}
		catch (IOException e)
		{
			e.printStackTrace();
		}

	}

}
